﻿using Microsoft.AspNetCore.Mvc;
using WorldmeServer.Models.用户相关;
using WorldmeServer.Services.Business.衣柜相关;

namespace WorldmeServer.Controllers.衣柜相关
{
    [ApiController]
    [Route("api/closet")]
    public class ClosetController : ControllerBase
    {
        private readonly ClosetService closetService;
        public ClosetController(ClosetService closetService)
        {
            this.closetService = closetService;
        }

        [HttpGet]
        [Route("get/{type}")]
        public async Task<IActionResult> Get(string type)
        {
            var user = HttpContext.Items["User"] as User;
            var result = await closetService.GetTextures(user.Id, type);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }

        [HttpPost]
        [Route("add/{textureId}")]
        public async Task<IActionResult> Add(string textureId)
        {
            var user = HttpContext.Items["User"] as User;
            var result = await closetService.AddTexture(user.Id, textureId);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }

        [HttpDelete]
        [Route("delete/{textureId}")]
        public async Task<IActionResult> Delete(string textureId)
        {
            var user = HttpContext.Items["User"] as User;
            var result = await closetService.DeleteTexture(user.Id, textureId);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }

        [HttpGet]
        [Route("has/{textureId}")]
        public async Task<IActionResult> Has(string textureId)
        {
            var user = HttpContext.Items["User"] as User;
            var result = await closetService.HasTexture(user.Id, textureId);
            if (!result.IsSuccess)
                return BadRequest(result.Message);
            return Ok(result.Data);
        }
    }
}
